package com.dwusoft.banks.controller;

import java.io.PrintWriter;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import utils.EncryptAndSignService;
import utils.HttpUtils;

@Controller
public class AppAccountController {
	
	private final static Logger logger = LoggerFactory.getLogger(AppAccountController.class);
	
	@RequestMapping(value = "/cipher")
	public void p2pHome(String custNo,String plainTxt,HttpServletRequest request,  HttpServletResponse response) throws Exception{
		System.out.println(HttpUtils.getRequestParameters(request));;
		
		request.setCharacterEncoding("UTF-8");
		response.setCharacterEncoding("UTF-8");
		PrintWriter pw = response.getWriter();
		if(null == custNo || "".equals(custNo) || null==plainTxt || "".equals(plainTxt)){
			pw.print("paramters not null 参数不能为空");
			pw.flush();
		}else{
			EncryptAndSignService eass = new EncryptAndSignService(custNo,plainTxt);
			logger.info(eass.getCipherTxt());
			if(eass.encryptAndSign(custNo)){
				pw.print(eass.getCipherTxt());
			}
		}
		
		pw.flush();
		pw.close();
		
	}
	
	
}
